package model.entities;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import model.persistence.HibernateSessionFactory;

import org.hibernate.classic.Session;

@Entity
@Table(name = "Areas")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "discriminator", discriminatorType = DiscriminatorType.INTEGER)
public abstract class Area
{
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	protected int id;
	
	@OneToOne
	@JoinColumn(name="idLocal")
	protected Local local;

	public static Map<AreaElaboracion, Collection<ItemMercaderia>> consultarMercaderiaAreas()
	{
		Map<AreaElaboracion, Collection<ItemMercaderia>> rv = new HashMap<AreaElaboracion, Collection<ItemMercaderia>>();
		Collection<AreaElaboracion> areasElaboracion = getAllAreasElaboracion();
		
		for(AreaElaboracion areaElaboracion : areasElaboracion)
		{
			rv.put(areaElaboracion, areaElaboracion.consultarMercaderia());
		}
		
		return rv;
	}

	public static Area getArea(int idArea)
	{
		Session session = HibernateSessionFactory.getSessionFactory().openSession();
		return (Area)session.load(Area.class, idArea);
	}

	public Local getLocal()
	{
		return local;
	}

	public void setLocal(Local local)
	{
		this.local = local;
	}
	
	public static Collection<AreaElaboracion> getAllAreasElaboracion()
	{
		//TODO: get segun el discriminator
		return null;
	}
}
